package util;

import android.content.Context;
import android.graphics.Bitmap;

import com.tencent.mm.opensdk.modelmsg.SendMessageToWX;
import com.tencent.mm.opensdk.modelmsg.WXMediaMessage;
import com.tencent.mm.opensdk.modelmsg.WXWebpageObject;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;


/**
 * Created by fei on 2017/11/24.
 */

public class ShareUtil {
    /*public static void qqfx(Activity activity, String url, String title, String description, String imgUrl, Tencent mTencent, IUiListener qqShareListener,String appname) {
        final Bundle params = new Bundle();
        params.putInt(QQShare.SHARE_TO_QQ_KEY_TYPE,
                QQShare.SHARE_TO_QQ_TYPE_DEFAULT);
        params.putString(QQShare.SHARE_TO_QQ_TITLE, title);
        params.putString(QQShare.SHARE_TO_QQ_SUMMARY, description);
        params.putString(QQShare.SHARE_TO_QQ_TARGET_URL, url);
        params.putString(QQShare.SHARE_TO_QQ_IMAGE_URL, imgUrl);
        params.putString(QQShare.SHARE_TO_QQ_APP_NAME, appname);
        mTencent.shareToQQ(activity, params, qqShareListener);
    }
    public static void shareToQzone(Activity activity, String url, String title, String description, String imgUrl, Tencent mTencent, IUiListener qqShareListener) {
        Bundle params = new Bundle();
        ArrayList<String> imageUrls = new ArrayList<String>();
        imageUrls.add(imgUrl);
        params.putString(QzoneShare.SHARE_TO_QQ_TITLE, title);// 必填
        params.putString(QzoneShare.SHARE_TO_QQ_SUMMARY, description);// 选填
        params.putString(QzoneShare.SHARE_TO_QQ_TARGET_URL, url);// 必填
        params.putStringArrayList(QzoneShare.SHARE_TO_QQ_IMAGE_URL, imageUrls);
        mTencent.shareToQzone(activity, params, qqShareListener);
    }*/
    public static void shareToweixin(Context context,String url, String title, String description, Bitmap thumb, String appid) {
        WXWebpageObject webpage = new WXWebpageObject();
        webpage.webpageUrl = url;
        WXMediaMessage msg = new WXMediaMessage(webpage);
        msg.title = title;
        msg.description = description;
        //这里替换一张自己工程里的图片资源
        msg.setThumbImage(thumb);
        SendMessageToWX.Req req = new SendMessageToWX.Req();
        req.transaction = String.valueOf(System.currentTimeMillis());
        req.message = msg;
        req.scene = SendMessageToWX.Req.WXSceneSession;
        IWXAPI api = WXAPIFactory.createWXAPI(context, appid);
        api.registerApp(appid);
        api.sendReq(req);
    }


    public static void shareToweixinp(Context context,String url, String title, String description, Bitmap thumb, String appid) {
        WXWebpageObject webpage = new WXWebpageObject();
        webpage.webpageUrl = url;
        WXMediaMessage msg = new WXMediaMessage(webpage);
        msg.title = title;
        msg.description = description;
        //这里替换一张自己工程里的图片资源
        msg.setThumbImage(thumb);
        SendMessageToWX.Req req = new SendMessageToWX.Req();
        req.transaction = String.valueOf(System.currentTimeMillis());
        req.message = msg;
        req.scene = SendMessageToWX.Req.WXSceneTimeline;
        IWXAPI api = WXAPIFactory.createWXAPI(context, appid);
        api.registerApp(appid);
        api.sendReq(req);
    }
    /*private static int shareType = QQShare.SHARE_TO_QQ_TYPE_DEFAULT;
    public static IUiListener qqShareListener = new IUiListener() {
        @Override
        public void onCancel() {
            if (shareType != QQShare.SHARE_TO_QQ_TYPE_IMAGE) {
                Log.e("onCancel: ","share");
            }
        }

        @Override
        public void onComplete(Object response) {
            Log.e("onComplete: " ,"+"+ response.toString());
        }

        @Override
        public void onError(UiError e) {
           Log.e("onError: " ,"+"+ e.errorMessage);
        }
    };*/
}
